package com.kould.key;

import com.kould.encoder.CacheEncoder;
import com.kould.encoder.impl.BaseCacheEncoder;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Component
public class ArticleKeyGenerator implements KeyGenerator {
    private CacheEncoder encoder = BaseCacheEncoder.getInstance();

    @Override
    public Object generate(Object o, Method method, Object... objects) {
        return o.getClass().getName() + method.getName() +
                Stream.of(objects).map(encoder::argsEncode).collect(Collectors.joining(","));
    }
}
